package com.vueuploadimg.demo.Controller;

import org.springframework.stereotype.Controller;
import org.springframework.util.Base64Utils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @description：TODO
 * @Author MRyan
 * @Date 2020/4/17 12:05
 * @Version 1.0
 */
@RestController
@CrossOrigin
public class UploadController {

    @PostMapping("save")
    public String toupload(MultipartFile pic) throws IOException {
        System.out.println(pic);
        String s = Base64Utils.encodeToString(pic.getBytes());
        //直接将s存储到数据库中就可以了 数据库字段 mediumtext   排序规则utf8_general_ci
        //展示图片base64解码的时候:src data:image/png;base64,后面加上s
        return s;
    }

}
